﻿@using System.Text.RegularExpressions
@using BXJG.Common.Events
@inherits LayoutComponentBase
@inject NavigationManager Navigation
@implements IDisposable

<HeadContent>
    <link rel="stylesheet" href="ZLJ.Web.BlazorAuto.styles.css" />
    <link href="/app.css" rel="stylesheet" />
</HeadContent>



<div style="height:100vh">
    <ErrorBoundary @ref="errorBoundary">
        <ChildContent>
            
    <Layout>
        <Sider @bind-Collapsed=@MainMenuCollapsed NoTrigger Collapsible >
            <div class="logo" style="height:29px; margin:15px;">
                <img src="bxjglogo.png" style="width:37px; height:30px; float:left;" />

                @if (!MainMenuCollapsed)
                {
                    <h3 style="    color: #ddd;    float: left;    margin-left: 0.5rem;    line-height: 35px;    font-size: 1.2rem;">
                        变形精怪  <Button OnClick="fancuo">xxxx</Button>
                    </h3>
                }
            </div>
            @* 菜单需要交互式 *@
            <MainMenu Collapsed=MainMenuCollapsed />
        </Sider>
        <Layout>
            <Header Class="zlj-main-head">
                <Flex Vertical=false Justify="space-between" Align="center" Style="height:100%;">
                    @* 左边 *@
                    <Flex Vertical=false Align="center">
                        @if (MainMenuCollapsed)
                        {
                            <Icon Type="menu-unfold" Theme="outline" Class="caidan-kaiguan"  OnClick="toggle" />
                        }
                        else
                        {
                            <Icon Type="menu-fold" Theme="outline" Class="caidan-kaiguan"  OnClick="toggle" />
                        }
                        @* <MainBreadcrumb style="padding-left:1rem;" /> *@
                    </Flex>
                    @* 右边 *@
                    <HeaderRight />
                </Flex>
            </Header>
            <Content>
                @if(auth)
                {
                    <ReuseTabs Class="zlj-main-body-box" TabPaneClass="zlj-main-tab-head-item" />
                }
                else
                {
                    <div class="zlj-main-body-box-no-auth">@Body</div>
                }
            </Content>
            <Footer Style="text-align: center; padding:0.3rem 0; color:rgba(100,100,100,0.7); height:3.5vh; position:fixed; z-index:999; width:100%; bottom:0;">
                Copyright ©1900-2024 变形精怪, All Rights Reserved | Power by <a href="https://dotnet.microsoft.com/zh-cn/apps/aspnet" target="_blank">asp.net 8.x</a> / <a href="https://aspnetboilerplate.com" target="_blank">abp 9.x</a> / <a href="https://antblazor.com" target="_blank">antblazor 0.17.x</a> / <a href="https://gitee.com/bxjg1987_admin/abp" target="_blank">源码</a>
            </Footer>
        </Layout>
    </Layout>


        </ChildContent>
        <ErrorContent>
            <Flex Style="height:50vh;" Align="center" Justify="center" Vertical="true">
      <div>
           ┗|｀O′|┛ 嗷~~程序出错啦！若多次输出错，请联系系统管理员。 <br />
                </div>
                <pre>   @XianshiCuowu(context) </pre>


           <Button Type="@ButtonType.Primary" OnClick="fanhui">返回</Button>
            </Flex>
        </ErrorContent>
    </ErrorBoundary>


</div>
@code {
    // [SupplyParameterFromQuery]
    // public int mmc { get; set; }

    string XianshiCuowu(Exception ex)
    {
#if DEBUG
    return ex.GetBaseException().StackTrace + Environment.NewLine;
#else
        return  Environment.NewLine; 
        #endif
    
    }

    // bool collapsed => mmc > 0;
    bool auth = false;
    private ErrorBoundary? errorBoundary;
    [Inject]
    public AuthenticationStateProvider AuthStateProvider { get; set; }
    [Inject]
    public Zhongjie Zhongjie { get; set; }

    bool MainMenuCollapsed;
    [Inject]
    public ILogger<StaticLayout> Logger { get; set; }
    //string LayoutStyle => "background-color:#f3f6fb; margin-left:" + (MainMenuCollapsed ? 80 : 200) + "px;transition-property: margin-left";
    void fanhui()
    {
        errorBoundary?.Recover();
    }
    void fancuo()
    {

        throw new Exception("xxxxxxxxxxxxxxx");
    }
    void toggle()
    {
        MainMenuCollapsed = !MainMenuCollapsed;
    }
   // IDisposable appContainerInited;
    protected override void OnInitialized()
    {
        // appContainerInited = Zhongjie.Zhuce( async () =>
        // {
        //     appContainerInited?.Dispose();
        //     this.Logger.LogDebug("全局状态初始化处理事件执行！");
        //     StateHasChanged();
        //     await InvokeAsync(StateHasChanged);

        // },"appContainerInited");
        base.OnInitialized();
    }
    public void Dispose()
    {
       // appContainerInited?.Dispose();
    }

    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();
        var zt = await AuthStateProvider.GetAuthenticationStateAsync();
        auth = zt != null && zt.User != default&& zt.User.Identity.IsAuthenticated;

      //  await Task.Delay(5000);
      //  InvokeAsync(StateHasChanged);
       // StateHasChanged();
    }
    // [Inject]
    // public IJSRuntime JSRuntime { get; set; }

    // protected override async Task OnAfterRenderAsync(bool firstRender)
    // {
    //     // if (firstRender)
    //     //{
    //     //Console.WriteLine("xxxxxxxxxxxxxxxxxxxxxxx");
    //     await JSRuntime.InvokeVoidAsync("hideLoadingDiv");
    //     //}
    // }
}